import 'package:dio/dio.dart' hide Headers;
import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';

import '../data/base_data.dart';
import '../data/const.dart';

part 'task_model.g.dart';

@RestApi(baseUrl: BASE_URL)
abstract class TaskApi {
  @GET("/task/task/list")
  Future<BaseData<List<TaskInfo>>> getTaskList();

  @POST("/task/task/add")
  @Headers({'Content-Type': 'application/json'})
  Future<BaseData<TaskEntity>> addTask(@Body() TaskEntity task);

  @GET("/task/task/detail/{id}")
  Future<BaseData<TaskInfo>> getTaskDetail(@Path("id") int id);

  factory TaskApi(Dio dio, {String? baseUrl}) = _TaskApi;
}

@JsonSerializable()
class TaskInfo {
  int? id;
  String? taskTitle;
  bool? isCompleted;
  String? tips;
  DateTime? expectedStart;
  DateTime? expectedEnd;
  bool? doing;
  DateTime? startTime;
  DateTime? endTime;
  List<TaskStep>? stepList;

  TaskInfo(
      {this.id,
      this.taskTitle,
      this.isCompleted,
      this.tips,
      this.expectedStart,
      this.expectedEnd,
      this.doing,
      this.startTime,
      this.endTime,
      this.stepList});

  factory TaskInfo.fromJson(Map<String, dynamic> json) =>
      _$TaskInfoFromJson(json);

  Map<String, dynamic> toJson() => _$TaskInfoToJson(this);
}

@JsonSerializable()
class TaskStep {
//   {"id":3,"taskId":0,"stepTitle":"111222333","complete":false,"createTime":"0001-01-01T00:00:00Z","updateTime":"0001-01-01T00:00:00Z"}
  int? id;
  int? taskId;
  String? stepTitle;
  bool? complete;

  TaskStep({this.id, this.taskId, this.stepTitle, this.complete});

  factory TaskStep.fromJson(Map<String, dynamic> json) =>
      _$TaskStepFromJson(json);

  Map<String, dynamic> toJson() => _$TaskStepToJson(this);
}

@JsonSerializable()
class TaskEntity {
  int? id;
  String? taskTitle;
  bool? isCompleted;
  String? tips;
  DateTime? expectedStart;
  DateTime? expectedEnd;
  bool? doing;
  DateTime? startTime;
  DateTime? endTime;
  List<String>? stepList;

  TaskEntity(
      {this.id,
      this.taskTitle,
      this.isCompleted,
      this.tips,
      this.expectedStart,
      this.expectedEnd,
      this.doing,
      this.startTime,
      this.endTime,
      this.stepList});

  factory TaskEntity.fromJson(Map<String, dynamic> json) =>
      _$TaskEntityFromJson(json);

  Map<String, dynamic> toJson() => _$TaskEntityToJson(this);
}
